//
//  ValueTransformer.m
//  exSync
//
//  Created by Alexander Chaika on 25.01.12.
//  Copyright 2012 by Alexander Chaika. All rights reserved.
//

#import "ValueTransformer.h"


@implementation StartSyncTransformerForLabel

+ (Class)transformedValueClass {
    return [NSString class];
}

+ (BOOL)allowsReverseTransformation {
    return NO;
}

- (id)transformedValue:(id)value {
	BOOL running = [value boolValue];
	if (running)
		return [NSString stringWithString:@"exSync is running"];
	return [NSString stringWithString:@"exSync is stopped"];
}

@end

@implementation StartSyncTransformerForButton

+ (Class)transformedValueClass {
    return [NSString class];
}

+ (BOOL)allowsReverseTransformation {
    return NO;
}

- (id)transformedValue:(id)value {
	BOOL running = [value boolValue];
	if (running)
		return [NSString stringWithString:@"Stop exSync"];
	return [NSString stringWithString:@"Start exSync"];
}

@end

@implementation LastSyncDateTransformer

+ (Class)transformedValueClass {
    return [NSString class];
}

+ (BOOL)allowsReverseTransformation {
    return NO;
}

- (id)transformedValue:(id)value {
	if (!value)
		return [NSString stringWithString:@"never synced"];
	
	// date format
	NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
	[dateFormatter setDateStyle:NSDateFormatterFullStyle];
	[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];

	return [dateFormatter stringFromDate:value];
}

@end

@implementation ScheduledSyncDateTransformer

+ (Class)transformedValueClass {
    return [NSString class];
}

+ (BOOL)allowsReverseTransformation {
    return NO;
}

- (id)transformedValue:(id)value {
	if (!value)
		return [NSString stringWithString:@"not scheduled"];
	
	// date format
	NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
	[dateFormatter setDateStyle:NSDateFormatterFullStyle];
	[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
	
	return [dateFormatter stringFromDate:value];
}

@end
